Repository navigation
Load the cron handler without importing the ES-module route, compare CRON_SECRET in constant time, and read any NPM_CONFIG_DRY_RUN value but false, 0 or empty as a dry run (#67) - #68
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request carries one commit, the follow-up fixes listed in #67: the cron route's request handler moves into
lib/cron.jsso tests load it withrequire()instead of importing the ES-module route file, theCRON_SECRETbearer comparison goes throughcrypto.timingSafeEqualon equal-length SHA-256 digests, and the PyPI country collector readsnpm_config_dry_runset to any value other thanfalse,0or empty as a dry run. The README and a test comment that gave the wrong edit distance are corrected to match.Included
What the code on this branch does:
pages/api/cron/collect.jsis now two lines: it importscronHandlerfromlib/cron.jsand exports it as the default. A test reads the route file and asserts exactly those two lines.isAuthorizedreturns false whenCRON_SECRETis unset or empty or when the header is not a string; otherwise it compares the SHA-256 digest of the header with the digest ofBearer <secret>usingcrypto.timingSafeEqual. The test asserts thatBearer s3cretis accepted, thatBearer s3cresand a longer wrong token are refused, that an array header is refused without reaching the comparison, and that each comparison receives two buffers of equal length.npmDryRunmatches the variable namenpm_config_dry_runin any letter case and treats the value, trimmed and lower-cased, as a dry run unless it is empty,falseor0. The tests asserttrue,TRUE,True,1andyesselect a dry run andfalse,FALSE,False,0and empty do not, and thatNPM_CONFIG_DRY_RUN=TRUEand=1without credentials take the dry-run path, exit 1 with "nothing was measured", and write no run status file.Verified on this exact tree
Run with Node 24.21.0, the version both workflows and
.node-versionselect.npm ci --no-audit --no-fund: completed, native module for better-sqlite3 built.npm run build(next build): exit 0, "Compiled successfully", 3 of 3 static pages generated.node --test --test-concurrency=4 test/*.test.js: 18 test files; 258 tests, 258 passed, 0 failed, 0 cancelled, 0 skipped.git status --porcelainafter the tests and the build printed nothing.No pre-existing or load-related failures: every test passed in the single full run.
Not included
None.
How to merge
Rebase and merge, so that each change stays its own commit on
main.